package twistter;

import java.awt.Dimension;
import java.awt.Image;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;

public class Tweet {
	
	public final static Dimension imageSize = new Dimension(80,80);
	
	private BufferedImage image;
	private String name;
	private String content;
	private boolean favorite;

	public Tweet(URL pathToImage, String name, String content) throws IOException {
		this.setImage(ImageIO.read(pathToImage));
		this.setName(name);
		this.setContent(content);
	}
	
	// Getters and setters :
	public BufferedImage getImage() {
		return image;
	}
	public void setImage(BufferedImage image) {
		int w = image.getWidth();
		int h = image.getHeight();
		BufferedImage after = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
		AffineTransform at = new AffineTransform();
		at.scale(((double)imageSize.width)/((double)w)+0.4, ((double)imageSize.height)/((double)h)+0.4);
		AffineTransformOp scaleOp = 
		   new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
		after = scaleOp.filter(image, after);
		this.image = scaleOp.filter(image, after);
		//this.image = (BufferedImage) image.getScaledInstance(80, 80, Image.SCALE_SMOOTH);
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public boolean isFavorite() {
		return favorite;
	}
	public void setFavorite(boolean favorite) {
		this.favorite = favorite;
	}

}
